package com.bentley.kotlindemo.ui.kits.authorlist_paging

import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import androidx.paging.*
import com.bentley.kotlindemo.base.BaseViewModel
import com.bentley.kotlindemo.repository.AuthorPagingRepository

/**
 * <pre>
 *  ┌────────────────────────────────────────────
 *  │ @author  Lee  @date 2021/3/24 18:05
 *  ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
 *  │ @desc
 *  └────────────────────────────────────────────
 * </pre>
 */
class AuthorPagingModel :BaseViewModel(){
    private val repository:AuthorPagingRepository by lazy { AuthorPagingRepository() }

     val name:MutableLiveData<String> by lazy {
        MutableLiveData<String>()
    }

//    fun getArticleData1() =
//        Pager(PagingConfig(pageSize = 20, prefetchDistance = 10)) { PostDataSource(RetrofitBuilder.apiService) }.flow

    /**
     * Pager 分页入口 每个PagingData代表一页数据
     */
    suspend fun getArticleData() = repository.getArticleData().cachedIn(viewModelScope)
    override fun onCleared() {
        super.onCleared()
        Log.e("AuthorPagingModel","onCleared销毁")
    }
}